<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        img {
            width: 100px;
            height: 100px;
        }
    </style>
</head>

<body>
    <div id="imgList">
        <!--<img src="https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=518705001,2876224431&fm=11&gp=0.jpg" alt="">
                <img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=153960715,2502274764&fm=26&gp=0.jpg" alt="">
                <img src="https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1474266791,210202337&fm=26&gp=0.jpg" alt="">-->
        <!--<img id="img1"  src="favicon.ico" alt="">-->
    </div>
    <script>
        // let imgDiv = document.getElementById("imgList");
        // console.log(imgDiv.style);
        // imgDiv.style.height = "1000px";
        // imgDiv.onload = function () {
        //     console.log("div onload")
        // }
        // console.dir(imgDiv);
        // let loadImg = (src) => {
        //     return new Promise((resolve, reject) => {
        //         //创建一个图片标签
        //         let img = document.createElement("img");
        //         img.src = src;
        //         img.onload = () => {//加载成功后的回调函数
        //             resolve(img)
        //         };
        //         img.onerror = () => {//加载失败后的回调函数
        //             reject(new Error("图片加载失败"))
        //         };
        //     });
        // };

        // /*let p1 = new Promise((resolve, reject)=>{
        //     //创建一个图片标签
        //     let img = document.createElement("img");
        //     img.src = "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=518705001,2876224431&fm=11&gp=0.jpg";
        //     img.onload = ()=>{//加载成功后的回调函数
        //         resolve(img)
        //     };
        //     img.onerror = ()=>{//加载失败后的回调函数
        //         reject(new Error("图片加载失败"))
        //     };
        // });*/
        // let p1 = loadImg("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=518705001,2876224431&fm=11&gp=0.jpg");
        // let p2 = loadImg("https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=153960715,2502274764&fm=26&gp=0.jpg");
        // let p3 = loadImg("https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=1474266791,210202337&fm=26&gp=0.jpg");

        // //返回的也是一个promise对象
        // let pAll = Promise.all([p1, p2, p3]);

        // pAll.then(
        //     success => {
        //         console.log("pAll.then.success====>", success);//数组: [img1,img2,img3]
        //         let imgDiv = document.getElementById("imgList");
        //         success.map((item) => {
        //             imgDiv.appendChild(item)
        //         })
        //     },
        //     err => {
        //         console.log("pAll.then.err====>", err);
        //     }
        // );


        {
            //        let p1 = ()=> Promise.reject("hello");
            let p1 = () => Promise.resolve("hello");
            async function fn() {
                //即使前面异步操作出现问题,但是不影响代码继续执行
                try {
                    let res = await p1();
                    console.log("step3_1", res);
                } catch (e) {//捕获到的错误 e
                    console.log("step3_2___catch", e)
                }
                return await 110;
            }
            fn().then(
                res => {
                    console.log("step3_then方法", res)
                }
            )
        }


        
    </script>
</body>

</html>